package app.pumpkin.com.myandroiddemo;

import android.annotation.SuppressLint;
import android.content.ContentValues;
import android.database.Cursor;
import android.net.Uri;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;

import app.pumpkin.com.myandroiddemo.provider.Book;

/**
 * @author wangshy
 */
public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        ContentValues values = new ContentValues();
        values.put("_id", "5");
        values.put("name", "Kotlin");
        getContentResolver().insert(Uri.parse("content://cn.wangshy.Provider"), values);

        @SuppressLint("Recycle") Cursor bookCursor = getContentResolver().query(Uri.parse("content://cn.wangshy.Provider"), new String[]{"_id", "name"}, null, null, null);
        assert bookCursor != null;
        while (bookCursor.moveToNext()) {
            Book book = new Book();
            book.setBookId(bookCursor.getInt(0));
            book.setName(bookCursor.getString(1));
            Log.d("-----", "query book:" + book.toString());
        }
    }
}
